import type { BasicQueryParams, BasicResult, PaginationResult } from '../core';

import { requestClient } from '../request';

export namespace GroupApi {
  const URL = '/auth/group';
  /** 用户组返回值 */
  export interface GroupResult extends BasicResult {
    name: string;
  }

  /**
   * 查询用户组
   */
  export async function listGroup(params: BasicQueryParams) {
    return requestClient.get<PaginationResult<GroupResult>>(URL, {
      params,
      withCredentials: true,
    });
  }

  /**
   * 获取用户组
   */
  export async function retrieveGroup(id: string) {
    return requestClient.get<GroupResult>(`${URL}/${id}`, {
      withCredentials: true,
    });
  }
  /**
   * 创建用户组
   */
  export async function createGroup(data: Partial<GroupResult>) {
    return requestClient.post<GroupResult>(`${URL}`, data, {
      withCredentials: true,
    });
  }
  /**
   * 更新用户组
   */
  export async function updateGroup(id: string, data: Partial<GroupResult>) {
    return requestClient.patch<GroupResult>(`${URL}/${id}`, data, {
      withCredentials: true,
    });
  }
  /**
   * 删除用户组
   */
  export async function deleteGroup(id: string) {
    return requestClient.delete<any>(`${URL}/${id}`, {
      withCredentials: true,
    });
  }
}
